package flexbars.controls
{

import flash.errors.IllegalOperationError;

//--------------------------------------
//  Events
//--------------------------------------

//--------------------------------------
//  Styles
//--------------------------------------

//--------------------------------------
//  Excluded APIs
//--------------------------------------

//--------------------------------------
//  Other metadata
//--------------------------------------

public class ITF25 extends Code25
{
	
	//--------------------------------------------------------------------------
	//
	//  Constructor
	//
	//--------------------------------------------------------------------------
	
	public function ITF25()
	{
		super();
	}
	
	//--------------------------------------------------------------------------
	//
	//  Constants
	//
	//--------------------------------------------------------------------------
	
	//--------------------------------------------------------------------------
	//
	//  Variables
	//
	//--------------------------------------------------------------------------
	
	//--------------------------------------------------------------------------
	//
	//  Overridden properties
	//
	//--------------------------------------------------------------------------
	
    //----------------------------------
    //  code
    //----------------------------------
	
	override public function set code(value:String):void
	{
		if ( (value.length % 2) != 0 )
			throw new ArgumentError("");
		
		super.code = value;
	}
	
	//--------------------------------------------------------------------------
	//
	//  Properties
	//
	//--------------------------------------------------------------------------
	
	//--------------------------------------------------------------------------
	//
	//  Overridden methods
	//
	//--------------------------------------------------------------------------
	
    //----------------------------------
    //  encode
    //----------------------------------
	
	override protected function encode():void
	{
		bars = [];
		
		// start sequence
		bars.push(1, 1, 1, 1);
		
		var n:int = code.length;
		for (var i:int = 0; i < n; i += 2)
		{
			encodeDigits( parseInt( code.substr(i, 2) ) );
		}
		
		// end sequence
		bars.push(2, 1, 1);
	}
	
	//--------------------------------------------------------------------------
	//
	//  Methods
	//
	//--------------------------------------------------------------------------
	
    //----------------------------------
    //  encodeDigits
    //----------------------------------
	
	private function encodeDigits(digits:int):void
	{
		if (digits < 00 || digits > 99)
			throw new ArgumentError("ITF25 encodeDigits digits");
		
		var a:int = digits / 10;
		var b:int = digits % 10;
		
		for (var i:int = 0; i < 5; i++)
		{
			bars.push(DIGIT_ENCODING[a][i], DIGIT_ENCODING[b][i]);
		}
	}
	
	//--------------------------------------------------------------------------
	//
	//  Overridden event handlers
	//
	//--------------------------------------------------------------------------
	
	//--------------------------------------------------------------------------
	//
	//  Event handlers
	//
	//--------------------------------------------------------------------------
	
}

}